<?php

namespace app\admin\service\goods;

use app\traits\Result;
use app\common\model\GoodsLayout as GoodsLayoutModel;


class GoodsLayOutService
{
    use Result;

    /**
     * 添加/编辑
     * @param $data
     * @param string $scene
     * @return array|string
     */
    public static function storeGoodsLayout($data,$scene='add'){
        $data['state'] = isset( $data['state'])? $data['state']:0;
        $data['update_time'] = time();

        $model = new GoodsLayoutModel(); //实例化
        if(!empty($data) && !empty($data['name'])) {
            if ($scene == 'add') {
                $data['create_time'] = time();
                $data['wxapp_id'] = 1001;

                $result = $model->save($data);
                if ($result) {
                    return Result::success('添加成功');
                } else {
                    return Result::error('添加失败');
                }
            } else {
                //$result = $model->where(['id'=>$data['id']])->find();
                unset($data['token']);
                $result = $model->exists(true)->update($data);
                //   $result->save($data);
                if ($result) {
                    return Result::success('编辑成功');
                } else {
                    return Result::error('编辑失败');
                }
            }
        }
        return false;
    }
    
}